home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Paths Regions and Clipping / KeyholeClipCentered / KeyholeClipCentered.cs next >
Encoding:
Text File  |  2001-01-15  |  922 b   |  30 lines

  1. //--------------------------------------------------
  2. // KeyholeClipCentered.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class KeyholeClipCentered: KeyholeClip
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new KeyholeClipCentered());
  13.      }
  14.      public KeyholeClipCentered()
  15.      {
  16.           Text += " Centered";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           grfx.SetClip(path);
  21.  
  22.           RectangleF rectf   = path.GetBounds();
  23.           int        xOffset = (int)((cx - rectf.Width)  / 2 - rectf.X);
  24.           int        yOffset = (int)((cy - rectf.Height) / 2 - rectf.Y);
  25.  
  26.           grfx.TranslateClip(xOffset, yOffset);
  27.           grfx.DrawImage(image, xOffset, yOffset, image.Width, image.Height);
  28.      }
  29. }
  30.